package g

import (
	"sync"

	"github.com/name5566/leaf/gate"

	"github.com/name5566/leaf/chanrpc"
)

var Userinfo sync.Map
var UserIdIndex int64

type UserData struct {
	Id          int64 // 玩家UID
	GameCode    string
	GameCodeBet string
	State       string //conduct=进行中  matching=匹配中
	Agent       gate.Agent
	Lang        string //玩家语言
}

var (
	DbRpc   *chanrpc.Server
	GameRpc *chanrpc.Server
	G1      *chanrpc.Server
	//FarmRpc   *chanrpc.Server
	//FamilyRpc *chanrpc.Server
	//MailRpc   *chanrpc.Server
)

func Keys[K comparable, V any](m map[K]V) []K {
	keys := make([]K, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}
	return keys
}

// 发送消息
func Send(ids []int64, gameCode string, args interface{}) {
	GameRpc.Go("Push", ids, gameCode, args)
}

//func ToObjs(obj interface{}, obj2 interface{}) {
//	result := map[int64]map[string]interface{}{}
//	mapstructure.Decode(obj2, &result)
//
//}
//
//func ToObjs2(args interface{}, list interface{}) {
//	type CardInfo struct {
//		CardList []int64
//	}
//	arr := []CardInfo{}
//	if reflect.TypeOf(list).String() == "[][]int64" {
//		rr := list.([][]int64)
//		for _, v := range rr {
//			a := CardInfo{}
//			a.CardList = v
//			arr = append(arr, a)
//		}
//		copier.Copy(args, &arr)
//	}
//	arr2 := map[int64]CardInfo{}
//	if reflect.TypeOf(list).String() == "map[int64][]int64" {
//		rr := list.(map[int64][]int64)
//		for k, v := range rr {
//			a := CardInfo{}
//			a.CardList = v
//			arr2[k] = a
//		}
//		copier.Copy(args, &arr2)
//	}
//}
//
//func DeepCopy(dst, src interface{}) error {
//	var buf bytes.Buffer
//	if err := gob.NewEncoder(&buf).Encode(src); err != nil {
//		return err
//	}
//	return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst)
//}
//
//func GetOpenSession() int64 {
//	int64Num, _ := strconv.ParseInt(strings.ReplaceAll(carbon.Now().ToDateString()+"0000", "-", ""), 10, 64)
//	return int64Num + carbon.Parse(carbon.Now().ToDateString()+" 00:00:00").DiffAbsInMinutes(datetime)/5 + 1
//}
